package com.oocl.homework.random;

public class MyRandom {
	
	public  int myRandom(int from,int to,int number,int rate) throws Exception{
		if (to<=from) {
			throw new Exception("to must great than from");
		}
		if (number<from||number>to) {
			throw new Exception("number out of boundary");
		}
		if (rate>100||rate<0) {
			throw new Exception("rate out of boundary");
		}
		int t = randFromTo(1, 100);
		int result =-1;
		if (t<=rate) {
			return number;
		}
		if(t>rate){
			do {
				result = randFromTo(from, to);
			} while (result==number);
		}
				
		return result;
		
	}

	
	public  int randFromTo(int from,int to) throws Exception{
		if (to<=from) {
			throw new Exception("to must great than from");
		}
		int rs = (int) (Math.random()*(to-from+1))+from;
		return rs;
	}
}
